package leetcode.primary;

import java.util.ArrayList;
import java.util.List;


public class T155 {
    Stack stack1;   //真实栈
    Stack stack2;   //辅助栈，存当前真实栈中最小值

    /** initialize your data structure here. */
    public T155() {
        stack1 = new Stack();
        stack2 = new Stack();
    }

    public void push(int val) {
        stack1.push(val);
        if (stack1.isempty()){
            stack2.push(val);
        }else if (val<=stack2.getTop()){
            stack2.push(val);
        }
    }

    public void pop() {
        if (stack1.isempty()){
            return;
        }
        if (stack1.getTop()<= stack2.getTop()){
            stack2.pop();
        }
        stack1.pop();
    }

    public int top() {
        if (stack1.isempty()){
            return -1;
        }
        return stack1.getTop();
    }

    public int getMin() {
        if (stack1.isempty()){
            return -1;
        }
        return stack2.getTop();
    }

}

class Stack{
    int top=0;
    List<Integer> list = new ArrayList<>();

    void pop(){
        list.remove(list.size()-1);
        top--;
    }

    void push(int val){
        list.add(val);
        top++;
    }

    int getTop(){
        return list.get(top-1);
    }

    boolean isempty(){
        return top == 0;
    }

}